package com.young.shop.admin.controller;


import com.young.shop.admin.service.CouponService;
import com.young.shop.admin.service.DataService;
import com.young.shop.pojo.entity.Coupon;
import com.young.shop.pojo.qo.CartsInfoQO;
import com.young.shop.pojo.vo.BaseRespVO;
import com.young.shop.pojo.vo.CenterDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 创建优惠券
 */

@Api(tags = "优惠券中心业务")
@RestController
@RequestMapping("/Coupon")
public class CouponController extends BaseController {
    @Autowired
    private CouponService couponService;

    @ApiOperation("生成优惠券")
    @PostMapping("/creatCoupon")
    public BaseRespVO createCoupon(@RequestBody Coupon coupon){
        System.out.println("创建优惠券");
        System.out.println(coupon.toString());
        try {
            int serviceCoupon = couponService.createCoupon(coupon);
            System.out.println(serviceCoupon);
            return convertSuccessResult(serviceCoupon);
        } catch (RuntimeException e) {
            String errorMsg = e.getMessage();
            System.out.println(errorMsg);
            return convertErrorResult(errorMsg);
        }
    }

}
